//
// Created by LoveHoneyYou on 2024-11-16.
//

#ifndef WEBSERVER_BUFFER_H
#define WEBSERVER_BUFFER_H

#include <string>


class Buffer
{
public:
    Buffer(int size);
    ~Buffer();

    int Append_Buffer(const char* data,int size);
    int Append_Buffer(const char* data);
    int Append_Buffer (const std::string& data);
    int Socket_Read(int fd);
    char* Find_CRLF();
    int Send_Data(int socket);

    inline char* Read_Start_Data()
    {
        return data_+read_pos_;
    }

    inline int Read_Pos_Inscrease(int count)
    {
        read_pos_ += count;
        return read_pos_;
    }

    inline int Read_Able_Size()
    {
        return write_pos_ - read_pos_;
    }

    inline int Write_Able_Size()
    {
        return capacity_ - read_pos_;
    }


    //扩容
    void Extend_Room(int size);

private:
    char* data_;
    int capacity_;
    int read_pos_ = 0;
    int write_pos_ = 0;
    char* tmpbuf_ = nullptr;
};



#endif//WEBSERVER_BUFFER_H
